package com.exp.bookhouse.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.exp.bookhouse.pojo.Book;
import com.exp.bookhouse.pojo.vo.StockVo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface BookMapper extends BaseMapper<Book>{

    @Update("update tb_book set stock = stock - #{bookNum} where id = #{bookId}")
    int updateStock(@Param("bookId") Long bookId, @Param("bookNum") Integer bookNum);

    @Select("select id, stock from tb_book where id = #{bookId}")
    @Results({
            @Result(column = "id",property = "bookId"),
            @Result(column = "stock",property = "stock")
    })
    StockVo queryStockById(Long bookId);
}
